<?php

abstract class HiveCliActivity extends AsyncActivity {

    public function __construct($activity) {
   		parent::__construct($activity);       
    }
    
    protected function prepare() {
    	if(!parent::prepare()) {
    		return false;
    	}
    	
    	$this->cmd = HIVE_CLIENT . " -e \"{$this->cmd}\"";
		return true;
    }
    
	// new function need to override by subclass
	protected function prepareInputs() {
		return true;
	}
	
	protected function prepareOutputs() {
		return true;
	}
    
	// override functions
	protected function getStatus() {
		// scan log to check whether this activity execute successfully.
		
		return true;
	}
	
	protected function getResultSize() {
		$statusLog = file_get_contents($this->statusPath);
        $pos = strpos($statusLog, 'total_size:');
        if($pos === false) {
            return parent::getResultSize();
        }

        preg_match('@\d+@', $statusLog, $matches, 0, $pos);
        return $matches[0];
    }
    
    protected function getResultCount() {
    	$statusLog = file_get_contents($this->statusPath);
        $pos = strpos($statusLog, ']');
        if($pos === false) {
            return parent::getResultSize();
        }

        preg_match('@\d+@', $statusLog, $matches, 0, $pos);
        return $matches[0];
    }
}
